﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace myLittleC
{
    class Program
    {
        static void About() 
        {
            Console.WriteLine("my Little C Language Compiler v0.2");
            Console.WriteLine("Author : Oleg \"Corwin\" Pinchuk, 236gr.");
            Console.WriteLine("Syntax : myLittleC -[l|px|ts] source");
            Console.WriteLine("   -l  start token analyzer");
            Console.WriteLine("   -px  start parsing expressions");
            Console.WriteLine("   -ts  write Symbol Table");
        }
        static void Main(string[] args)
        {
            try
            {
                if(args.Length < 2 )
                {
                    About(); return;
                }
            
                switch (args[0])
                {
                    case "-l":
                        Tokenizer tokenizer = new Tokenizer (args[1]);
                        for (Token  nToken = tokenizer.ActiveToken; TokenType.EOF != nToken.Type;  nToken = tokenizer.getNextToken())
                            Console.WriteLine(nToken.ToString());
                    break;
                    case "-px":
                    Parser s = new Parser(args[1]);
                        s.parse();
                        Console.WriteLine(s.ToString());
                    break;
                    case "-sd":
                    ParseWithSimpleeDef d = new ParseWithSimpleeDef(args[1]);
                        d.parse();
                        Console.WriteLine(d.ToString());
                    break;
                    case "-ts":
                        ParserWithStatement e = new ParserWithStatement(args[1]);
                        e.parse();
                        Console.WriteLine(e.WriteTable());
                    break;
                    default: About(); break;
                }
            }
            catch (ComExeption ex)
            {
                Console.WriteLine(ex);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }
            
        }
    }
}
